<?php
namespace ClubAdmin\Controller;
use Think\Controller;
class ClubController extends Controller {
    public function clubs(){

        $clubsModel=M('clubs');//构建一个操作clubs表的模型实例
        $clubs=$clubsModel->order('cl_id ')->select();
        $this->clubs=$clubs;
        $this->display();
       

    }
        public function  doUpdate($cl_id){
        $clubsInfos = M('clubs');
        // $data['cl_intro']=$_SESSION['cl_intro'];
        // $i = $data['cl_intro'];
        //接收用户输入的内容
        $data['cl_name'] = trim(I('post.cl_intro'));
        $data['cl_name'] = trim(I('post.cl_name'));
        $data['cl_tel'] = trim(I('post.cl_tel'));
        $data['cl_address'] = trim(I('post.cl_address'));

        $clubs=$clubsInfos->where("cl_id=$cl_id")->save($data);

        if(false !== $clubs){
            $this->success('修改成功！','clubs');
        }else{
            $this->error('修改失败');
        }
    }
   
     public  function editclubs($cl_id){
        $clubsInfos = M('clubs');
        $clubs=$clubsInfos->where("cl_id=$cl_id")->find();
        $this->clubsInfos=$clubs;
        $this->display();
    }

      public function addclubs()
  {
    if(IS_POST)
    {
      
      $data['cl_name'] = I('post.cl_name');
      $data['address'] = I('post.cl_address');
      $data['intro'] = I('post.cl_intro');
      $data['tel'] = I('post.cl_tel');
      
      
      if(empty($data['cl_name']))
      {
        $this->error('用户名必须填写');
      }
      else
      { 
        $clubs = M('clubs');
        if($clubs->create()){
            // $clubs->m_pic1=$name; 
            if(false!==$clubs->add())
                      {
                $this->success('添加成功!','clubs');
            }
            else{$this->error('添加失败');}
        }else{
            $this->error($clubs->getError());
        }
      }
    }
    else
    { 
      $this->display();
    } }   
    public function delclub($cl_id){
    $clubsmodel=M('clubs'); 
    //where实在构建条件
    if (false!==$clubsmodel->where("cl_id=$cl_id"/*必须是双引号*/)->delete()) {
            $this->success('删除成功！');
        } else {
            $this->error('删除失败');
        }
        
    }
}
?>